import pyodbc
f = file("conn.ini","r")
connstr = f.readline()
f.close()

def exeScalar(sql, parameters=None, sp=0):
    c = pyodbc.connect(connstr)
    if sp == 1:
        sql = "exec " + sql

    cs = c.cursor()
    cs.execute(sql,parameters)

    row = cs.fetchone()
    cs.close()
    c.commit()
    c.close()
    if row == None:
        return row
    else:
        return row[0]


def exeRow(sql, parameters=None, sp=0):
    c = pyodbc.connect(connstr)
    if sp == 1:
        sql = "exec " + sql

    cs = c.cursor()
    if parameters!=None:
        cs.execute(sql,parameters)
    else:
        cs.execute(sql)

    row = cs.fetchone()
    cs.close()
    c.close()

    return row


def exeTable(sql, parameters=None, sp=0):
    c = pyodbc.connect(connstr)
    if sp == 1:
        sql = "exec " + sql

    cs = c.cursor()
    if parameters!=None:
        cs.execute(sql,parameters)
    else:
        cs.execute(sql)
    des = cs.description
    dt = cs.fetchall()
    cs.close()
    c.close()

    return dt

def exeNonQuery(sql, parameters=None, sp=0):
    c = pyodbc.connect(connstr)
    if sp == 1:
        sql = "exec " + sql

    cs = c.cursor()

    if parameters!=None:
        cs.execute(sql,parameters)
    else:
        cs.execute(sql)

    c.commit()
    cs.close()
    c.close()


def __del__ ():
    c.close()